<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>My JSP 'Order.jsp' starting page</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<link rel="stylesheet" type="text/css"
			href="<%=basePath%>/css/biaoge.css" />
		<link rel="stylesheet" type="text/css"
			href="fancybox/jquery.fancybox-1.3.4.css" />
		<script type="text/javascript" src="jquery/js/jquery-1.8.2.js"></script>
		<script type="text/javascript"
			src="fancybox/jquery.easing-1.3.pack.js"></script>
		<script type="text/javascript" src="fancybox/jquery.fancybox-1.3.4.js"></script>
		<script type="text/javascript"
			src="fancybox/jquery.fancybox-1.3.4.pack.js"></script>
		<script type="text/javascript"
			src="fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
		<script type="text/javascript" src="<%=basePath%>/My97DatePicker/WdatePicker.js"></script>
<style type="text/css">
.go{width:47px;height:100px;background-color:#FFF;position:fixed;_position:absolute;_top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||200)-(parseInt(this.currentStyle.marginBottom,10)||0)));left:12px;bottom:25%;border-radius:5px;box-shadow:0 0 2px #6E6E6E}
.go a{background:url(images/a.gif) no-repeat;display:block;text-indent:999em;width:112px;margin:5px;border:0;overflow:hidden;float:left}
.go .top{background-position:-4px -42px;height:23px;width:37px;}
.go .refresh{background-position:-38px -42px;height:23px;width:37px;}
.go .bottom{background-position:-72px -42px;height:22px;width:37px;}
.go .top:hover{background-position:-4px -3px}
.go .refresh:hover{background-position:-38px -3px}
.go .bottom:hover{background-position:-72px -3px}
.back1{background-color:#FF9}
</style>
	</head>
	<script type="text/javascript">
  
   function fangda(tupian){
   $("#"+tupian+"k").fancybox();
  }
  
   function getone(a){
     window.location="orderdetail.action?orderid="+a;
   }
   
 
  
   function sele(){
  var time1=$("#time1").val();
  var time2 = $("#time2").val();
  alert(time1);
   var indusname=$("#gongchang").val();
   var orderId=$("#orderid").val();
   
   //alert("selectBydate.action?datetime='"+da+"'&&indusid="+indusid);
   
   window.location="selectBydate.action?startTime="+time1+"&&endTime="+time2+"&&indusname="+indusname+"&&page=1&&orderId="+orderId;
  }
  /**监听挺工厂反馈
  
   $(document).ready(function(){
   setInterval(
      ajaxfanstate
,5000);
   }
   );
   
  function ajaxfanstate(){
   var tm=$("#datetime").val();
   var indus=$("#indusname").val();
    $.post("selectorderbydate.action",
				{datetime:tm,indusname:indus},  
      		function(data){
      		//alert("asdfasdfasd");
      		 var len=data.jsonob.length;
      		 //$("#"+id+"").html("已发货");
      		 //var k='<font color="blue">已发货</font>';
      		 for(var i=0;i<len;i++)
      		 {
      		 if(data.jsonob[i].costFeedback!=null&&data.jsonob[i].costFeedback!=""){
      		 //alert("asda");
      		 document.getElementById(data.jsonob[i].orderId).innerHTML="工厂有反馈";
      		 }
      		 }
      		},
      		 "json"
      		);  
      		//alert("aaaaa");
  }
  **/
  function kai(a){
   var k=document.getElementById("zuihou");
  if(a<=1) k.innerHTML="这已经第一页了";
  }
  function zui(a,b){
  var z=document.getElementById("zuihou");
  if(a>=b) z.innerHTML="这已经是最后一页了";
  }
  $().ready(function() {
	var options = "<option value=''>---------全    部---------</option>";
       $.post(
       "getAllIndustry",
       function(data){
         $.each(data.gonglist,function(index,value){
        options = options+"<option value="+value.industryName+">"+value.industryName+"</option>";
        
         });
         $("#test").html(options);
       },"json"
       );
       $("select").click(function(){
       $("#gongchang").val($("select").val());
       });
       
       $.post("getAllProduct",function(data){
         var html1 = "";
         var sellerhtml = "";
         $.each(data.sellernames,function(i,v){
         var option="";
           if(v==null){
               
           }else{
                option = "<option value='"+v+"'>"+v+"</option>";
           }
           
           sellerhtml = sellerhtml+option;
         });
          $("#sellername").append(sellerhtml);
         $.each(data.products,function(i,v){
            var option = "<option value='"+v.alias+"' id="+v.productId+">"+v.productName+"</option>";
            html1 = html1+option;
         });
         $("#productName").append(html1);
         var pid = $("#productId").val();
         $("#"+pid).attr("selected","selected");
      });
       
	});
   
   function changep(){
    var id = $("#productName option:selected").attr("id");
    $("#productId").val(id);
   }
    function syncOrders(){
  $("#fancybox-overlay").css("display","block");
 	$("#loading_img").css("display","block");
      $.post("syncOrders",{"startTime":$("#start").val(),"day":$("#day").val()},function(data){
          alert("更新了"+data.num+"条数据");
           $("#fancybox-overlay").css("display","none");
 			$("#loading_img").css("display","none");
      });
   }
  </script>
   <a name="gotop">&nbsp;</a>
	<body>
	<div style="display:none;position:absolute;z-index:2000;left: 673px;top: 300px;background-color: white;text-align: center;" id="loading_img">
     <img src="img/022.gif" /><br/>
     同步数据中。。。
		</div>
	<div id="fancybox-overlay"
		style="background-color: rgb(119, 119, 119); height: 1823px; 
		opacity: 0.7; cursor: pointer; display: none; "
		></div>   
		<!--   <div style="margin-left:100px">   
<div style="float:right;margin-top:-70px">订单查询：<br>选择时间：<input type="text" name="riqi" id="riqi" onclick="JTC.setday({format:'yyyy-MM-dd', readOnly: true})"><br>
      工厂名称：<input type="text" name="gongchang" id="gongchang"><input type="button"  value="查询" onclick="sele()">
        </div>  -->

		<div align="center">
		<form action="selectBydate" method="post">
			<table>
				<tr>
					<td colspan="2" align="center">
						订单查询：
					</td>
				</tr>
				<tr>
					<td>
						选择时间：
					</td>
					<td colspan="2">
						<!--<input type="text" name="riqi" id="riqi" value="${datetime }"
							class="Wdate" onfocus="WdatePicker()">到：
						<input type="text" name="riqi" id="riqi" value="${datetime }"
							class="Wdate" onfocus="WdatePicker()">
						--><input type="text" id="time1" value="${startTime }" name="startTime"
						class="Wdate" onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'time2\')||\'2020-10-01\'}'})"/>
						至<input type="text" id="time2" value="${endTime }" name="endTime"
						class="Wdate" onFocus="WdatePicker({minDate:'#F{$dp.$D(\'time1\')}',maxDate:'2020-10-01'})"/>
					</td>
				</tr>
				<tr>
					<td>
						工厂名称：
					</td>
					<td colspan="2">
						<input type="text" name="indusname" id="gongchang" value="${indusname}">
						<select id="test"></select>
					</td>
				</tr>
				<tr>
					<td>
						交易编号：
					</td>
					<td>
						<input type="text" name="orderId" id="orderid" value="${orderId }">
						店铺名称：
						<select name="sellername" id="sellername">
						  <option value="" >全部</option>
						 
	               		</select><br/>
					</td>
				</tr>
				<tr>
					<td>
						产品名称：
					</td>
					<td>
						<select name="mark" id="productName" onchange="changep()">
						  <option value="" >全部</option>
	               		</select><br/>
	               		<input type="hidden" value="${productId }" name="productId"/>
					</td>
				</tr>
				<tr>
				<td>
						订单状态：
					</td>
					<td>
					
						<select name="orderstate">
						  <option value="-1" >全部</option>
						  <option value="0" ${orderstate=='0'?'selected':''}>买家申请退款</option>
						  <option value="1" ${orderstate=='1'?'selected':''}>未发货</option>
						  <option value="2" ${orderstate=='2'?'selected':''}>已发货</option>
						  <option value="3" ${orderstate=='3'?'selected':''}>交易成功</option>
						  <option value="4" ${orderstate=='4'?'selected':''}>交易关闭</option>
						</select>
					</td>
				</tr>
				<tr>
					<td colspan="2" align="center">
						<input type="submit" value="查询">
					</td>
					<td colspan="2" align="center">
					  
						<input type="button" value="同步数据" onclick="syncOrders()">
						开始时间：<input type="text" id="start" value="${startTime }" 
						class="Wdate" onFocus="WdatePicker()"/>
						同步天数：
						<select id="day">
						<option value="1">1天</option>
						<option value="2">2天</option>
						<option value="3">3天</option>
						<option value="4">4天</option>
						</select>
					</td>
				</tr>
			</table>
			</form>
		</div>




		<div align="center" id="order">
			<!-- <div style="width:1000px;margin-left: 150px;margin-top:70px" id="order"> -->
			<font size="3" color="red">${datetime}${indusname}的订单如下：如果没有制作CDR文件，可以点击订单详细信息查看图片制作然后上传图片即可。</font>
			<table id="mytable" cellspacing="0" width="950">
				<tr>
					<td>
						交易编号
					</td>
					<td>
						订单图片
					</td>
					<td>
						订单名字
					</td>
					<td>
						订单数量
					</td>
					<td>
						下单用户
					</td>
					<td>
						下单时间
					</td>
					<td>
						订单详细信息
					</td>
					<td>
						订单对应工厂
					</td>
					<td>
						快递单号
					</td>
					<td>
						订单状态
					</td>
					<td>
						是否制作CDR文件
					</td>
					
					<td width="50px;">
						标签
					</td>
				</tr>
				<c:forEach items="${trades}" var="trade" varStatus="ts">
				<c:forEach items="${trade.orders}" var="order" varStatus="os">
					<c:if test="${!empty order.orderName}">
						<tr class="${ts.index%2==0?'back1':'' }">
						<c:if test="${os.index==0}">
							<td rowspan="${trade.count*2 }">
								${order.tradeId}
							</td>
					    </c:if>
							<td>
								<c:choose>
							     <c:when test="${fn:startsWith(order.orderPic,'描述')}">
							     ${order.orderPic }
							     </c:when>
							     <c:otherwise>
							     <img src="${order.orderPic}" style="height:76px;width:100px""/>
							  	 <a id="${order.orderId}k" href="${order.orderPic}"><img src="img/fangda.gif" onclick="fangda('${order.orderId}')" style="float: right;"></a>
							     </c:otherwise>
							     </c:choose>
							</td>
							<td>
								${order.orderTheme}
							</td>
							<td>
								${order.orderProductsCount}
							</td>
							<td>
								${order.userName}
							</td>
							<td>
								<fmt:formatDate value="${order.orderTime}"
									pattern="yyyy-MM-dd HH:mm:ss" />
							</td>
							<td>
								<input type="button" value="查看详细信息"
									onclick="getone('${order.orderId}')">
							</td>
							<c:if test="${os.index==0}">
							<td rowspan="${trade.count*2 }">
								${order.industryName}
							</td>
							<td rowspan="${trade.count*2 }">
								${order.orderFreight}
							</td>
							</c:if>
							<c:choose>
								<c:when test="${order.orderState==0}">
									<td id="${order.orderId}">
										<font size="2" color="black">用户申请退款</font>
									</td>
								</c:when>

								<c:when test="${order.orderState==1}">
									<td id="${order.orderId}">
										<font size="2" color="red">未发货</font>
										<c:if test="${! empty order.costFeedback}">
											<font size="2" color="red">工厂有反馈</font>
										</c:if>
									</td>
								</c:when>

								<c:when test="${order.orderState==2}">
									<td id="${order.orderId}">
										<font size="2" color="blue">已发货</font>
										<c:if test="${! empty order.costFeedback}">
											<font size="2" color="blue">工厂有反馈</font>
										</c:if>
									</td>
								</c:when>

								<c:when test="${order.orderState==3}">
									<td id="${order.orderId}">
										<font size="2" color="green">交易成功</font>
									</td>
								</c:when>
								
								<c:when test="${order.orderState==4}">
									<td id="${order.orderId}">
										<font size="2" color="grey">交易关闭</font>
									</td>
								</c:when>
								    
								<c:otherwise>
								  <td id="${order.orderId}">
										<font size="2" color="grey">异常订单</font>
									</td>
								</c:otherwise>

							</c:choose>
							</c:if>
                            
							
								<td>
									${order.CDRurl!=null||order.orderState==2?'<font size=2 color=blue>已制作</font>':'<font size=2 color=red>未制作</font>' }
								</td>
							
							<c:if test="${os.index==0}">
							<td rowspan="${trade.count*2 }">
							${order.sellername}
							</td>
							
							</c:if>
							<tr>
					
				</c:forEach>
			</c:forEach>
			</table>
			<div style="margin-left: 350px; margin-top: 50px">
			共有订单<font color=red>${total }</font>条
				<a href="selectBydate.action?page=1"> 首页</a>&lt;
				<a href="selectBydate.action?page=${pagenow-1}"
					onclick="kai(${pagenow})">上一页</a>
				<strong>第${pagenow}页/共${pagecount}页</strong>
				<a href="selectBydate.action?page=${pagenow+1}"
					onclick="zui(${pagenow},${pagecount})"> 下一页</a>&gt;
				<a href="selectBydate.action?page=${pagecount}">末页</a>&gt;&gt;
				</p>
				<font size="2" color="red" id="zuihou"></font>
			</div>
			
			<br>
		
		</div>
		
		<div
			style="width: 980px; height: 0px; background: #EEE; margin: 0 auto;"></div>
		<a name="gobottom">&nbsp;</a>
		<div class="go">
			<a title="返回顶部" class="top" href="selectBydate#gotop"></a>
			<a title="刷新" class="refresh" href="javascript:void()" onclick="location.reload()"></a>
			<a title="返回底部" class="bottom" href="selectBydate#gobottom"></a>
		</div>

	</body>
</html>
